package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.BaseParamBo;
import com.cskaoyan.bean.BaseRespData;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.pojo.Keyword;
import com.cskaoyan.service.admin.KeywordService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Name : KeywordController.java
 * @Time : 2021/8/13 11:43
 * @Author : Xfeng
 * @Software : IntelliJ IDEA
 */
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @RequiresPermissions(value = {"*", "admin:keyword:list"}, logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo list(String keyword, String url, BaseParamBo baseParamBo) {
        BaseRespData baseRespData = keywordService.list(keyword, url, baseParamBo);
        return BaseRespVo.ok(baseRespData);
    }

    @RequiresPermissions(value = {"*", "admin:keyword:create"}, logical = Logical.OR)
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Keyword keyword) {
        if (keyword.getUrl() == null || keyword.getUrl().equals("")) {
            return BaseRespVo.fail("跳转链接不能为空");
        }
        Keyword keyword1 = keywordService.create(keyword);
        return BaseRespVo.ok(keyword1);
    }

    @RequiresPermissions(value = {"*", "admin:keyword:update"}, logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Keyword keyword) {
        if (keyword.getUrl() == null || keyword.getUrl().equals("")) {
            return BaseRespVo.fail("跳转链接不能为空");
        }
        Keyword keyword1 = keywordService.update(keyword);
        return BaseRespVo.ok(keyword1);
    }

    @RequiresPermissions(value = {"*", "admin:keyword:delete"}, logical = Logical.OR)
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Keyword keyword) {
        keywordService.delete(keyword);
        return BaseRespVo.ok();
    }

}
